package tedu.shoot;
import java.awt.image.BufferedImage;


public class Hero extends FlyingObject{
    private int life;
    private int fire;
    public  Hero(){
        super(97,139,140,400);
        life = 3;
        fire = 0;
    }

    public void step(){}

    public void moveTo(int x, int y){
        this.x = x-this.width/2;
        this.y = y-this.height/2;
    }

    public Bullet[] shoot(){
        int xStep = this.width/5;
        int yStep = 20;
        if (fire>500){
            Bullet[] bs = new Bullet[5];
            for (int i=0;i< bs.length;i++) {
                bs[i] = new Bullet(this.x + i * xStep, this.y - yStep);
            }
            fire-=bs.length;
            return bs;
        } else if (fire>100){
            Bullet[] bs = new Bullet[fire/100];
            for (int i=0;i< bs.length;i++) {
                bs[i] = new Bullet(this.x + i * xStep, this.y - yStep);
            }
            fire-=bs.length;
            return bs;
        } else{
            Bullet[] bs =new Bullet[1];
            bs[0] = new Bullet(this.x+2*xStep,this.y-yStep);
            return bs;
        }
    }

    public void addFire(){
        fire+=50;
    }

    public void addLife(){
        life += 1;
    }

    public int getLife(){
        return life;
    }

    public int getFire(){ return fire; }

    public void subtractLife(){
        life--;
    }

    public void clearFire(){
        fire = 0;
    }

    private int index = 0;
    public BufferedImage getImage() {
        return Images.heros[index++%Images.heros.length];
    }

}

